<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form" action="" lay-filter="search-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">短链</label>
                            <div class="layui-input-inline">
                                <input type="text" name="surl" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">访问IP</label>
                            <div class="layui-input-inline">
                                <input type="text" name="accessIp" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">访问时间</label>
                            <div class="layui-inline" id="ID-laydate-rangeLinked">
                                <div class="layui-input-inline">
                                    <input type="text" name="startTime" autocomplete="off" id="startTime" class="layui-input" placeholder="开始日期">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input type="text" name="endTime" autocomplete="off" id="endTime" class="layui-input" placeholder="结束日期">
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon layui-icon-search"></i>搜 索
                            </button>
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-reset-btn">
                                <i class="layui-icon layui-icon-refresh"></i> 重 置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <div class="layuimini-table">
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
    </div>
</div>

<script type="text/html" id="currentTableBar">
    <a class="layui-btn layui-bg-purple layui-btn-xs" lay-event="detail">详情</a>
</script>

<script type="text/html" id="detailDialog">
    <div class="layuimini-form">
        <div class="layui-form">
            <div class="layui-row">
                <div class="layui-col-md12">
                    <div class="layui-form-item label-super-wide">
                        <label class="layui-form-label"><b>日志ID：</b></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid" id="id" style="word-break: break-all"></div>
                        </div>
                    </div>
                    <div class="layui-form-item label-super-wide">
                        <label class="layui-form-label"><b>短链：</b></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid" id="surl" style="word-break: break-all"></div>
                        </div>
                    </div>
                    <div class="layui-form-item label-super-wide">
                        <label class="layui-form-label"><b>访问时间：</b></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid" id="accessTime" style="word-break: break-all"></div>
                        </div>
                    </div>
                    <div class="layui-form-item label-super-wide">
                        <label class="layui-form-label"><b>访问IP：</b></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid" id="accessIp" style="word-break: break-all"></div>
                        </div>
                    </div>
                    <div class="layui-form-item label-super-wide">
                        <label class="layui-form-label"><b>访问IP归属地：</b></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid" id="accessAddress" style="word-break: break-all"></div>
                        </div>
                    </div>
                    <div class="layui-form-item label-super-wide">
                        <label class="layui-form-label"><b>userAgent：</b></label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid" id="accessUserAgent" style="word-break: break-all"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>

<script>
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;


        // 日期范围 - 左右面板联动选择模式
        laydate.render({
            elem: '#ID-laydate-rangeLinked',
            range: ['#startTime', '#endTime'],
            rangeLinked: true // 开启日期范围选择时的区间联动标注模式 ---  2.8+ 新增
        });


        var currTable = table.render({
            elem: '#currentTableId',
            url: '/tenant/accessLog/query',
            method: 'post',
            contentType: 'application/json',
            request: {
                pageName: 'pageNo',
                limitName: 'pageSize'
            },
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.data.totalCount,
                    "data": res.data.records
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                {type: 'numbers', width: '5%', title: '序号', align: 'center'},
                {field: 'id', width: '10%', title: '日志ID', align: 'center'},
                {field: 'surl', width: '10%', title: '短链', align: 'center'},
                {field: 'accessTime', width: '15%', title: '访问时间'},
                {field: 'accessIp', width: '15%', title: '访问IP'},
                {field: 'accessAddress', width: '15%', title: '访问IP归属地'},
                {field: 'accessUserAgent', width: '25%', title: 'userAgent'},
                {title: '操作', minWidth: '5%', toolbar: '#currentTableBar', align: "center"}
            ]],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // 执行搜索重载
            table.reloadData('currentTableId', {
                page: {
                    curr: 1
                },
                where: data.field
            });
            return false;
        });

        // 监听重置操作
        form.on('submit(data-reset-btn)', function (data) {
            form.val("search-form", {
                "accessIp": '',
                "endTime": '',
                "startTime": '',
                "surl": ''
            });
            // 执行搜索重载
            table.reloadData('currentTableId', {
                page: {
                    curr: 1
                },
                where: form.val("search-form")
            });
            return false;
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var lineData = obj.data;
            if (obj.event === 'detail') {
                var index = layer.open({
                    title: '日志详情',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['1000px', '500px'],
                    content: $('#detailDialog').html(),
                    success: function (layero, dIndex) {
                        layero.find('#id').text(lineData.id);
                        layero.find('#surl').text(lineData.surl);
                        layero.find('#accessTime').text(lineData.accessTime);
                        layero.find('#accessIp').text(lineData.accessIp);
                        layero.find('#accessAddress').text(lineData.accessAddress);
                        layero.find('#accessUserAgent').text(lineData.accessUserAgent);
                    },
                    end: function (index) {
                    }
                });

            }
        });

    });
</script>